home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Cream of the Crop 22
/
Cream of the Crop 22.iso
/
bbs
/
pad321.zip
/
IN.MH
< prev
next >
Wrap
Text File
|
1996-08-21
|
13KB
|
459 lines
// (C) 1995 Stefan Xenos
//
#ifndef __IN_MH
#define __IN_MH
#ifndef __UPCHAR_MH
#include "upchar.mh"
#endif
#ifndef __COUNTCHA_MH
#include "countcha.mh"
#endif
#ifndef __STRIPSTR_MH
#include "stripstr.mh"
#endif
#ifndef __INSETUP_MH
#include "insetup.mh"
#endif
#define ANI_SPINNER "/|\\-"
#define ANI_FILL "░▒▓█▓▒░ "
#define ANI_FILL_SPIN "▄▌▀▐"
#define ANI_META "_-+|│ìïî|┤┐─═≡=-∙°ºouUÜÖo"
#define ANI_QUESTION "¿?"
#define ANI_LINES "┐┬┌├└┴┘┤"
#define ANIMATION_OFF 0,""
//#define ANI_WEIRD "ÇüéâäàåçêëèïîìÄÅÉæÆôöòûùÿÖÜ¢£¥₧ƒáíóúñѪº¿⌐¬½¼¡«»░▒▓│┤Y╢╖╕╣║╗╝╜╛┐└┴┬├─┼╞╟╚╔╩╦╠═╬╧╨╤╥╙╘╒╓╫╪┘┌█▄▌▐▀αßΓπΣσµτΦΘΩδ∞φε∩≡±≥≤⌠⌡÷≈°∙·√ⁿ²■"
#define KB_BS (8)
#define KB_CR (13)
#define KB_CTRL_@ (0)
#define KB_CTRL_A (1)
#define KB_CTRL_B (2)
#define KB_CTRL_C (3)
#define KB_CTRL_D (4)
#define KB_CTRL_E (5)
#define KB_CTRL_F (6)
#define KB_CTRL_G (7)
#define KB_CTRL_H (8)
#define KB_CTRL_I (9)
#define KB_CTRL_J (10)
#define KB_CTRL_K (11)
#define KB_CTRL_L (12)
#define KB_CTRL_M (13)
#define KB_CTRL_N (14)
#define KB_CTRL_O (15)
#define KB_CTRL_P (16)
#define KB_CTRL_Q (17)
#define KB_CTRL_R (18)
#define KB_CTRL_S (19)
#define KB_CTRL_T (20)
#define KB_CTRL_U (21)
#define KB_CTRL_V (22)
#define KB_CTRL_W (23)
#define KB_CTRL_X (24)
#define KB_CTRL_Y (25)
#define KB_CTRL_Z (26)
#define KB_CTRL_PGUP (128+4)
#define KB_F11 (128+5)
#define KB_F12 (128+6)
#define KB_SHIFT_F11 (128+7)
#define KB_SHIFT_F12 (128+8)
#define KB_CTRL_F11 (128+9)
#define KB_CTRL_F12 (128+10)
#define KB_ALT_F11 (128+11)
#define KB_ALT_F12 (128+12)
#define KB_CTRL_UP (128+13)
#define KB_CTRL_CENTER (128+15)
#define KB_CTRL_DOWN (128+17)
#define KB_CTRL_INS (128+18)
#define KB_CTRL_DEL (128+19)
#define KB_ALT_UP (128+24)
#define KB_ALT_LEFT (128+27)
#define KB_ALT_RIGHT (128+29)
#define KB_ALT_DOWN (128+32)
#define KB_F1 (128+59)
#define KB_F2 (128+60)
#define KB_F3 (128+61)
#define KB_F4 (128+62)
#define KB_F5 (128+63)
#define KB_F6 (128+64)
#define KB_F7 (128+65)
#define KB_F8 (128+66)
#define KB_F9 (128+67)
#define KB_F10 (128+68)
#define KB_HOME (128+71)
#define KB_UP (128+72)
#define KB_PGUP (128+73)
#define KB_LEFT (128+75)
#define KB_CENTER (128+76)
#define KB_RIGHT (128+77)
#define KB_END (128+79)
#define KB_DOWN (128+80)
#define KB_PGDN (128+81)
#define KB_INS (128+82)
#define KB_DEL (128+83)
#define KB_SHIFT_F1 (128+84)
#define KB_SHIFT_F2 (128+85)
#define KB_SHIFT_F3 (128+86)
#define KB_SHIFT_F4 (128+87)
#define KB_SHIFT_F5 (128+88)
#define KB_SHIFT_F6 (128+89)
#define KB_SHIFT_F7 (128+90)
#define KB_SHIFT_F8 (128+91)
#define KB_SHIFT_F9 (128+92)
#define KB_SHIFT_F10 (128+93)
#define KB_CTRL_F1 (128+94)
#define KB_CTRL_F2 (128+95)
#define KB_CTRL_F3 (128+96)
#define KB_CTRL_F4 (128+97)
#define KB_CTRL_F5 (128+98)
#define KB_CTRL_F6 (128+99)
#define KB_CTRL_F7 (128+100)
#define KB_CTRL_F8 (128+101)
#define KB_CTRL_F9 (128+102)
#define KB_CTRL_F10 (128+103)
#define KB_CTRL_LEFT (128+115)
#define KB_CTRL_RIGHT (128+116)
#define KB_CTRL_END (128+117)
#define KB_CTRL_PGDN (128+118)
#define KB_CTRL_HOME (128+119)
// Global variables -------------------------------------------------------
int: maxAnimationPos, animationPos, num_show_response, speed;
string: animation, animationColour, textColour;
// The following variables control the behaviour of the input_list_ani routine
void animationOff () {
maxAnimationPos := 0;
animation := "";
}
void useAnimation (string: newAnimation, string: newAnimationColour,
string: newTextColour, int: newAnimationSpeed) {
speed := newAnimationSpeed;
animation := newAnimation;
animationColour := newAnimationColour;
textColour := newTextColour;
animationPos := 1;
maxAnimationPos := strlen (animation);
if (newAnimationSpeed = 0) animationOff ();
}
int waitKey (int: maxLength) {
int: counter;
for (counter := 0; (counter < maxLength); counter := counter + 3) {
if (kbhit ()) return True;
sleep (3);
};
return False;
}
void keystallAni () {
int: counter;
if (maxAnimationPos = 0) {
for (;kbhit () = 0;);
return;
};
if (kbhit ()) return;
for (;;) {
print (animation [animationPos]);
animationPos := animationPos + 1;
if (animationPos > maxAnimationPos) animationPos := 1;
print (AVATAR_LEFT);
if (waitKey (speed)) {
if (usr.video = 0) {
print ('\b');
print (' ');
print ('\b');
return;
};
print (" ");
print (AVATAR_LEFT);
return;
};
if (usr.video = 0) {
print ('\b');
};
};
}
void flushInput () {
for (;kbhit ();getch ());
}
char getchExtended () {
int: result;
result := getch ();
if (usr.video = 0) return result;
if (result = 0) {
if (waitKey (20) = False) {
return 0;
};
return 128 + getch ();
};
if (result = 27) {
if (waitKey (20) = False) {
return 27;
};
result := getch ();
if (result <> '[') {
return result;
};
do {
if (waitKey (20) = False)
return '[';
result := upChar (getch ());
} while ((result >= '0') and (result <= '9'));
if (result = 'A') return KB_UP;
if (result = 'B') return KB_DOWN;
if (result = 'C') return KB_RIGHT;
if (result = 'D') return KB_LEFT;
if (result = 'H') return KB_HOME;
if (result = 'K') return KB_END;
if (result = 'L') return KB_CTRL_HOME;
if (result = 'M') return KB_CTRL_PGUP;
};
return result;
}
char getchAni () {
char: result;
print (animationColour);
if (maxAnimationPos > 0) keystallAni ();
result := getchExtended ();
print (textColour);
vidsync ();
return result;
}
void readStrAni (Ref string: theString) {
int: idx, slen;
char: key;
int: counter;
idx := 1;
slen := 0;
theString := "";
for (;;) {
if (idx = slen + 1) {
key := getchAni ();
}
else key := getchExtended ();
if (key = KB_BS) {
if (idx > 1) {
idx := idx - 1;
slen := slen - 1;
if (idx = slen + 1) {
theString := substr (theString,1,slen);
print ('\b');
print (" ");
print ('\b');
}
else {
string: newString;
newString := substr (theString, idx+1, slen - idx + 1);
print (AVATAR_LEFT);
theString := substr (theString,1,idx-1) + newString;
print (newString + " ");
for (counter := 0; counter <= strlen (newString); counter := counter + 1) {
print (AVATAR_LEFT);
};
};
};
}
else if (key = KB_CR) {
print ("\n");
return;
}
else if (key = KB_HOME) {
for (; idx > 1; idx := idx - 1) {
print (AVATAR_LEFT);
};
}
else if (key = KB_END) {
for (; idx <= slen; idx := idx + 1) {
print (theString [idx]);
};
}
else if ((key = KB_LEFT) and (idx > 1)) {
print (AVATAR_LEFT);
idx := idx - 1;
}
else if ((key = KB_CTRL_LEFT) and (idx > 1)) {
counter := idx - 1;
while ((counter > 1) and (theString [counter] = ' ')) {
counter := counter - 1;
};
while ((counter > 1) and (theString [counter] <> ' ')) {
counter := counter - 1;
};
if ((slen > 1) and (theString [counter] = ' ') and (counter > 1))
counter := counter + 1;
for (;counter < idx; idx := idx - 1) {
print (AVATAR_LEFT);
};
vidsync ();
}
else if ((key = KB_CTRL_RIGHT) and (idx <= slen )) {
counter := idx;
while ((counter <= slen) and (theString [counter] = ' ')) {
counter := counter + 1;
};
while ((counter <= slen) and (theString [counter] <> ' ')) {
counter := counter + 1;
};
for (;counter > idx; idx := idx + 1) {
print (theString [idx]);
};
vidsync ();
}
else if ((key = KB_RIGHT) and (idx <= slen)) {
print (theString [idx]);
idx := idx + 1;
}
else if (key = KB_CTRL_Y) {
for (;idx > 1; idx := idx - 1) {
print ('\b');
};
slen := 0;
print (AVATAR_CLEOL);
theString := "";
}
else if ((key = KB_DEL) and (idx <= slen)) {
string: newString;
slen := slen - 1;
newString := substr (theString, idx+1, slen - idx + 1);
theString := substr (theString,1,idx-1) + newString;
print (newString + " ");
for (counter := 0; counter <= strlen (newString); counter := counter + 1) {
print (AVATAR_LEFT);
};
}
else if ((key = KB_CTRL_L) or (key = KB_CTRL_W)) {
for (counter := 1; counter < idx; counter := counter + 1) {
print ('\b');
};
print (theString);
vidsync ();
for (counter := 0; counter < slen - idx + 1; counter := counter + 1) {
print (AVATAR_LEFT);
};
vidsync ();
}
else if (key > 127) {
}
else {
idx := idx + 1;
slen := slen + 1;
if (idx = slen + 1) {
print (key);
theString [idx - 1] := key;
}
else {
string: newString;
print (key);
vidsync ();
newString := substr (theString,idx - 1,slen + 1 - idx);
print (newString);
vidsync ();
theString := substr (theString,1,idx - 2);
theString [idx - 1] := key;
vidsync ();
theString := theString + newString;
for (counter := 0; counter < slen - idx + 1; counter := counter + 1) {
print (AVATAR_LEFT);
};
};
};
};
}
string choiceStr (string: values) {
int: idx, tidx;
string: result;
tidx := 2;
stripStr (values, "\r\n\b");
result [1] := '[';
for (idx := 1; idx < strlen (values); idx := idx + 1) {
result [tidx] := values [idx];
tidx := tidx + 1;
result [tidx] := ',';
tidx := tidx + 1;
};
result [tidx] := values [idx];
result := result + "]:";
return result;
}
char input_list_ani (string: values, string: error, string: prompt) {
char: key;
string: choices;
string: chStr;
chStr := choiceStr (values);
if (usr.ibmchars) {
useAnimation (KEY_ANI, KEY_ANI_COL, KEY_TEXT_COL, KEY_ANI_SPEED);
}
else useAnimation (KEY_ANI_NOIBM, KEY_ANI_COL, KEY_TEXT_COL, KEY_ANI_SPEED);
choices := strupper (values);
for (;;) {
print (PROMPT_COL);
print (prompt);
if (SHOW_CHOICES) print (" " + CHOICE_COL + chStr + " ");
key := upChar (getchAni ());
if (SHOW_USER_INPUT) print (key);
print ('\n');
if (countChar (choices, key)) {
return key;
};
print (ERROR_COL);
print (error);
};
}
void input_str_ani (Ref string: theString) {
if (usr.ibmchars) {
useAnimation (STR_ANI, STR_ANI_COL, STR_TEXT_COL, STR_ANI_SPEED);
}
else useAnimation (STR_ANI_NOIBM, STR_ANI_COL, STR_TEXT_COL, STR_ANI_SPEED);
readStrAni (theString);
}
#endif